package com.glsc.ngateway.flowable.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @Author: zzp
 * @Date: 20200527
 * @Desc: 多DataSource配置
 */

@Configuration
public class DataSourceDefConfig {
    private static Logger logger = LoggerFactory.getLogger(DataSourceDefConfig.class);

    public static final String DS_MYSQL = "datasourceMysql";
    public static final String DS_MYSQL_GATEWAY = "datasourceMysqlGateway";


    @Bean(name = "mysqlflowable")
    @ConfigurationProperties(prefix = "spring.datasource.mysql")
    public DataSourceProperties mysqlflowable() {
        return new DataSourceProperties();
    }

    @Bean(name = DS_MYSQL)
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource.mysql.hikari")
    public DataSource datasourceMysql() {
        return mysqlflowable().initializeDataSourceBuilder().build();
    }

    @Bean(name = "mysqlgateway")
    @ConfigurationProperties(prefix = "spring.datasource.mysqlgateway")
    public DataSourceProperties mysqlgateway() {
        return new DataSourceProperties();
    }

    @Bean(name = DS_MYSQL_GATEWAY)
    @ConfigurationProperties("spring.datasource.mysqlgateway.hikari")
    public DataSource datasourceMysqlGateway() {
        return mysqlgateway().initializeDataSourceBuilder().build();
    }

}